#include <iostream>
#include <fstream>
#include <chrono>
#include <ratio>
#include <iomanip>
#include <random>
#include <thread>
#include <functional>
#include <string>
#include <CL/sycl.hpp>

using namespace cl::sycl;
using gauss_func = std::function<void(buffer<float, 2>&, queue&)>;
std::string data_path = "../data.txt";

int main()
{
	int n = 4;
	srand((unsigned int)time(0));//初始化种子为随机值
	buffer<float, 2> buf(range(n, n + 1)); //创建一个scale*(scale + 1)大小的行列式 buffer 创建缓存区
	int x , max, min;
	max = 1024;
	min = -1024;

	host_accessor m{ buf ,read_write };
	// 数组初始化
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n + 1; j++)
		{
			m[i][j] = 0;
		}
	}

	// 对每一行除主元外的其他位置置随机数[-1024, 1024)
	// 先随机生成右三角行列式
	for (int i = 0; i < n; i++) 
	{
		m[i][i] = 1;
		for (int j = i + 1; j < n; j++)
			{
				x = min + rand() % (max - min + 1);
				m[i][j] = x;
			}
	}

	x = min + rand() % (max - min + 1);
	m[0][n] = x;

	// 然后逐行加下去
	for (int k = 0; k < n; k++) 
	{
		for (int i = k + 1; i < n; i++) 
		{
			for (int j = 0; j <= n; j++) 
			{
				m[i][j] += m[k][j];
				if( m[i][j] > max || m[i][j] < min)
				{
					m[i][j] /= i;
				}
			}
		}
	}

	std::ofstream o_file;
	o_file.open(data_path, std::ios::out); //保存数据
	o_file << n <<std::endl;

	auto range = m.get_range();
	for (int i = 0; i < range[0]; i++) {
		for (int j = 0; j < range[1]; j++) 
		{
			o_file << std::setw(16) << m[i][j];
		}
		o_file << std::endl;
	}
	o_file.close();
}
